<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
<meta name="generator" content="pdoc 0.9.2" />
<title>segmentation.utils API documentation</title>
<meta name="description" content="Utils functions." />
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/sanitize.min.css" integrity="sha256-PK9q560IAAa6WVRRh76LtCaI8pjTJ2z11v0miyNNjrs=" crossorigin>
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/typography.min.css" integrity="sha256-7l/o7C8jubJiy74VsKTidCy1yBkRtiUGbVkYBylBqUg=" crossorigin>
<link rel="stylesheet preload" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/styles/github.min.css" crossorigin>
<style>:root{--highlight-color:#fe9}.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}#sidebar > *:last-child{margin-bottom:2cm}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}h1:target,h2:target,h3:target,h4:target,h5:target,h6:target{background:var(--highlight-color);padding:.2em 0}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{margin-top:.6em;font-weight:bold}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}dt:target .name{background:var(--highlight-color)}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}td{padding:0 .5em}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style>
<style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%;height:100vh;overflow:auto;position:sticky;top:0}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style>
<style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style>
<script async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-AMS_CHTML" integrity="sha256-kZafAc6mZvK3W3v1pHOcUix30OHQN6pU/NO2oFkqZVw=" crossorigin></script>
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/highlight.min.js" integrity="sha256-Uv3H6lx7dJmRfRvH8TH6kJD1TSK1aFcwgx+mdg3epi8=" crossorigin></script>
<script>window.addEventListener('DOMContentLoaded', () => hljs.initHighlighting())</script>
</head>
<body>
<main>
<article id="content">
<header>
<h1 class="title">Module <code>segmentation.utils</code></h1>
</header>
<section id="section-intro">
<p>Utils functions.</p>
</section>
<section>
</section>
<section>
</section>
<section>
<h2 class="section-title" id="header-functions">Functions</h2>
<dl>
<dt id="segmentation.utils.ASPP"><code class="name flex">
<span>def <span class="ident">ASPP</span></span>(<span>x, filters)</span>
</code></dt>
<dd>
<div class="desc"></div>
</dd>
<dt id="segmentation.utils.CFF"><code class="name flex">
<span>def <span class="ident">CFF</span></span>(<span>input_list, input_size, filters, i)</span>
</code></dt>
<dd>
<div class="desc"></div>
</dd>
<dt id="segmentation.utils.MINI_MTL"><code class="name flex">
<span>def <span class="ident">MINI_MTL</span></span>(<span>inputs, filters, numClasses, i)</span>
</code></dt>
<dd>
<div class="desc"></div>
</dd>
<dt id="segmentation.utils.PEE"><code class="name flex">
<span>def <span class="ident">PEE</span></span>(<span>x, filters)</span>
</code></dt>
<dd>
<div class="desc"></div>
</dd>
<dt id="segmentation.utils.RA"><code class="name flex">
<span>def <span class="ident">RA</span></span>(<span>upsampled, high_level, filters)</span>
</code></dt>
<dd>
<div class="desc"></div>
</dd>
<dt id="segmentation.utils.build_MINI_MTL"><code class="name flex">
<span>def <span class="ident">build_MINI_MTL</span></span>(<span>input_shape, filters, numClasses, i)</span>
</code></dt>
<dd>
<div class="desc"></div>
</dd>
<dt id="segmentation.utils.calc_DM"><code class="name flex">
<span>def <span class="ident">calc_DM</span></span>(<span>seg)</span>
</code></dt>
<dd>
<div class="desc"><p>Computes NON-SIGNED Distance Map of input ground truth image or volume using scipy function.
In case seg is 3D volume, it separately computes 2D DM fo each single slice.</p>
<h2 id="args">Args</h2>
<dl>
<dt><strong><code>seg</code></strong></dt>
<dd>2D or 3D binary array to compute the distance map</dd>
</dl>
<h2 id="returns">Returns</h2>
<dl>
<dt><code>res</code></dt>
<dd>distance map</dd>
</dl></div>
</dd>
<dt id="segmentation.utils.calc_DM_batch"><code class="name flex">
<span>def <span class="ident">calc_DM_batch</span></span>(<span>y_true, numClasses)</span>
</code></dt>
<dd>
<div class="desc"><p>Prepares the input for NON-SIGNED Distance Map computation, and pass it to calc_DM</p>
<h2 id="args">Args</h2>
<dl>
<dt><strong><code>y_true</code></strong></dt>
<dd>ground truth tensor [class, batch, rows, columns, slices] or [class, batch, rows, columns]</dd>
<dt><strong><code>numClasses</code></strong></dt>
<dd>number of classes</dd>
</dl>
<h2 id="returns">Returns</h2>
<p>array of distance map of the same dimension of input tensor</p></div>
</dd>
<dt id="segmentation.utils.calc_DM_batch_edge"><code class="name flex">
<span>def <span class="ident">calc_DM_batch_edge</span></span>(<span>y_true, numClasses)</span>
</code></dt>
<dd>
<div class="desc"><p>Receives y_true mask labels, returns y_true contours and euclidean transform of y_true mask labels. Euclidean
transform is computed by the function 'calc_DM_edge'.</p>
<h2 id="args">Args</h2>
<dl>
<dt><strong><code>y_true</code></strong></dt>
<dd>ground truth tensor [class, batch, rows, columns, slices] or [class, batch, rows, columns]</dd>
<dt><strong><code>numClasses</code></strong></dt>
<dd>number of classes</dd>
</dl>
<h2 id="returns">Returns</h2>
<p>array of distance map of the same dimension of input tensor
array of ground truth contours of the same dimension of input tensor</p></div>
</dd>
<dt id="segmentation.utils.calc_DM_edge"><code class="name flex">
<span>def <span class="ident">calc_DM_edge</span></span>(<span>seg)</span>
</code></dt>
<dd>
<div class="desc"><p>Computes Non-Signed (Euclidean) Distance Map of input ground-truth volume CONTOURS using scipy function.
It separately computes 2D Distance Maps for each single slice in the volume.</p>
<h2 id="args">Args</h2>
<dl>
<dt><strong><code>seg</code></strong></dt>
<dd>3D binary volume of ground truth contours</dd>
</dl>
<h2 id="returns">Returns</h2>
<dl>
<dt><code>res</code></dt>
<dd>distance map</dd>
</dl></div>
</dd>
<dt id="segmentation.utils.calc_SDM"><code class="name flex">
<span>def <span class="ident">calc_SDM</span></span>(<span>seg)</span>
</code></dt>
<dd>
<div class="desc"><p>Computes SIGNED Distance Map of input ground truth image or volume using scipy function.
In case seg is 3D volume, it separately computes 2D SDM fo each single slice.</p>
<h2 id="args">Args</h2>
<dl>
<dt><strong><code>seg</code></strong></dt>
<dd>2D or 3D binary array to compute the distance map</dd>
</dl>
<h2 id="returns">Returns</h2>
<dl>
<dt><code>res</code></dt>
<dd>distance map</dd>
</dl></div>
</dd>
<dt id="segmentation.utils.calc_SDM_batch"><code class="name flex">
<span>def <span class="ident">calc_SDM_batch</span></span>(<span>y_true, numClasses)</span>
</code></dt>
<dd>
<div class="desc"><p>Prepares the input for SIGNED Distance Map computation, and pass it to calc_SDM</p>
<h2 id="args">Args</h2>
<dl>
<dt><strong><code>y_true</code></strong></dt>
<dd>ground truth tensor [class, batch, rows, columns, slices] or [class, batch, rows, columns]</dd>
<dt><strong><code>numClasses</code></strong></dt>
<dd>number of classes</dd>
</dl>
<h2 id="returns">Returns</h2>
<p>array of distance map of the same dimension of input tensor</p></div>
</dd>
<dt id="segmentation.utils.computeContours"><code class="name flex">
<span>def <span class="ident">computeContours</span></span>(<span>y_true, numClasses)</span>
</code></dt>
<dd>
<div class="desc"><p>Receive y_true masks and creates y_true contours.</p>
<h2 id="args">Args</h2>
<dl>
<dt><strong><code>y_true</code></strong></dt>
<dd>ground truth tensor [class, batch, rows, columns, slices] or [class, batch, rows, columns]</dd>
<dt><strong><code>numClasses</code></strong></dt>
<dd>number of classes</dd>
</dl>
<h2 id="returns">Returns</h2>
<p>array of ground truth contours [class, batch, rows, columns, slices]
number of contour voxels</p></div>
</dd>
<dt id="segmentation.utils.count_class_voxels"><code class="name flex">
<span>def <span class="ident">count_class_voxels</span></span>(<span>labels, nVoxels, numClasses)</span>
</code></dt>
<dd>
<div class="desc"><p>Counts total number of voxels for each class in the batch size.
input is supposed to be 4 or 5-dimensional: (class, batch, rows, columns) or
(class, batch, rows, columns, slices).</p>
<h2 id="args">Args</h2>
<dl>
<dt><strong><code>labels</code></strong></dt>
<dd>ground truth tensor of dimensions (class, batch_size, rows, columns, slices) or</dd>
<dt>(class, batch_size, rows, columns)</dt>
<dt><strong><code>nVoxels</code></strong></dt>
<dd>total number of voxels</dd>
<dt><strong><code>numClasses</code></strong></dt>
<dd>number of classes</dd>
</dl>
<h2 id="returns">Returns</h2>
<dl>
<dt><code>out</code></dt>
<dd>list with number of voxel per class</dd>
</dl></div>
</dd>
<dt id="segmentation.utils.cvtColor"><code class="name flex">
<span>def <span class="ident">cvtColor</span></span>(<span>src, code, dst, dstCn)</span>
</code></dt>
<dd>
<div class="desc"><p>cvtColor(src, code[, dst[, dstCn]]) -&gt; dst
.
@brief Converts an image from one color space to another.
. <br>
.
The function converts an input image from one color space to another. In case of a transformation
.
to-from RGB color space, the order of the channels should be specified explicitly (RGB or BGR). Note
.
that the default color format in OpenCV is often referred to as RGB but it is actually BGR (the
.
bytes are reversed). So the first byte in a standard (24-bit) color image will be an 8-bit Blue
.
component, the second byte will be Green, and the third byte will be Red. The fourth, fifth, and
.
sixth bytes would then be the second pixel (Blue, then Green, then Red), and so on.
. <br>
.
The conventional ranges for R, G, and B channel values are:
.
-
0 to 255 for CV_8U images
.
-
0 to 65535 for CV_16U images
.
-
0 to 1 for CV_32F images
. <br>
.
In case of linear transformations, the range does not matter. But in case of a non-linear
.
transformation, an input RGB image should be normalized to the proper value range to get the correct
.
results, for example, for RGB \f$\rightarrow\f$ L*u*v* transformation. For example, if you have a
.
32-bit floating-point image directly converted from an 8-bit image without any scaling, then it will
.
have the 0..255 value range instead of 0..1 assumed by the function. So, before calling #cvtColor ,
.
you need first to scale the image down:
.
@code
.
img *= 1./255;
.
cvtColor(img, img, COLOR_BGR2Luv);
.
@endcode
.
If you use #cvtColor with 8-bit images, the conversion will have some information lost. For many
.
applications, this will not be noticeable but it is recommended to use 32-bit images in applications
.
that need the full range of colors or that convert an image before an operation and then convert
.
back.
. <br>
.
If conversion adds the alpha channel, its value will set to the maximum of corresponding channel
.
range: 255 for CV_8U, 65535 for CV_16U, 1 for CV_32F.
. <br>
.
@param src input image: 8-bit unsigned, 16-bit unsigned ( CV_16UC&hellip; ), or single-precision
.
floating-point.
.
@param dst output image of the same size and depth as src.
.
@param code color space conversion code (see #ColorConversionCodes).
.
@param dstCn number of channels in the destination image; if the parameter is 0, the number of the
.
channels is derived automatically from src and code.
. <br>
.
@see @ref imgproc_color_conversions</p></div>
</dd>
<dt id="segmentation.utils.findContours"><code class="name flex">
<span>def <span class="ident">findContours</span></span>(<span>image, mode, method, contours, hierarchy, offset)</span>
</code></dt>
<dd>
<div class="desc"><p>findContours(image, mode, method[, contours[, hierarchy[, offset]]]) -&gt; contours, hierarchy
.
@brief Finds contours in a binary image.
. <br>
.
The function retrieves contours from the binary image using the algorithm @cite Suzuki85 . The contours
.
are a useful tool for shape analysis and object detection and recognition. See squares.cpp in the
.
OpenCV sample directory.
.
@note Since opencv 3.2 source image is not modified by this function.
. <br>
.
@param image Source, an 8-bit single-channel image. Non-zero pixels are treated as 1's. Zero
.
pixels remain 0's, so the image is treated as binary . You can use #compare, #inRange, #threshold ,
.
#adaptiveThreshold, #Canny, and others to create a binary image out of a grayscale or color one.
.
If mode equals to #RETR_CCOMP or #RETR_FLOODFILL, the input can also be a 32-bit integer image of labels (CV_32SC1).
.
@param contours Detected contours. Each contour is stored as a vector of points (e.g.
.
std::vector<std::vector\<cv::Point> >).
.
@param hierarchy Optional output vector (e.g. std::vector<cv::Vec4i>), containing information about the image topology. It has
.
as many elements as the number of contours. For each i-th contour contours[i], the elements
.
hierarchy[i][0] , hierarchy[i][1] , hierarchy[i][2] , and hierarchy[i][3] are set to 0-based indices
.
in contours of the next and previous contours at the same hierarchical level, the first child
.
contour and the parent contour, respectively. If for the contour i there are no next, previous,
.
parent, or nested contours, the corresponding elements of hierarchy[i] will be negative.
.
@param mode Contour retrieval mode, see #RetrievalModes
.
@param method Contour approximation method, see #ContourApproximationModes
.
@param offset Optional offset by which every contour point is shifted. This is useful if the
.
contours are extracted from the image ROI and then they should be analyzed in the whole image
.
context.</p></div>
</dd>
<dt id="segmentation.utils.get_loss_weights"><code class="name flex">
<span>def <span class="ident">get_loss_weights</span></span>(<span>labels, nVoxels, numClasses)</span>
</code></dt>
<dd>
<div class="desc"><p>Compute loss weights for each class.</p>
<h2 id="args">Args</h2>
<dl>
<dt><strong><code>labels</code></strong></dt>
<dd>ground truth tensor of dimensions (class, batch_size, rows, columns, slices) or</dd>
<dt>(class, batch_size, rows, columns)</dt>
<dt><strong><code>nVoxels</code></strong></dt>
<dd>total number of voxels</dd>
<dt><strong><code>numClasses</code></strong></dt>
<dd>number of classes</dd>
</dl>
<h2 id="returns">Returns</h2>
<p>1D tf.tensor of len = numClasses containing weights for each class</p></div>
</dd>
</dl>
</section>
<section>
</section>
</article>
<nav id="sidebar">
<h1>Index</h1>
<div class="toc">
<ul></ul>
</div>
<ul id="index">
<li><h3>Super-module</h3>
<ul>
<li><code><a title="segmentation" href="index.html">segmentation</a></code></li>
</ul>
</li>
<li><h3><a href="#header-functions">Functions</a></h3>
<ul class="two-column">
<li><code><a title="segmentation.utils.ASPP" href="#segmentation.utils.ASPP">ASPP</a></code></li>
<li><code><a title="segmentation.utils.CFF" href="#segmentation.utils.CFF">CFF</a></code></li>
<li><code><a title="segmentation.utils.MINI_MTL" href="#segmentation.utils.MINI_MTL">MINI_MTL</a></code></li>
<li><code><a title="segmentation.utils.PEE" href="#segmentation.utils.PEE">PEE</a></code></li>
<li><code><a title="segmentation.utils.RA" href="#segmentation.utils.RA">RA</a></code></li>
<li><code><a title="segmentation.utils.build_MINI_MTL" href="#segmentation.utils.build_MINI_MTL">build_MINI_MTL</a></code></li>
<li><code><a title="segmentation.utils.calc_DM" href="#segmentation.utils.calc_DM">calc_DM</a></code></li>
<li><code><a title="segmentation.utils.calc_DM_batch" href="#segmentation.utils.calc_DM_batch">calc_DM_batch</a></code></li>
<li><code><a title="segmentation.utils.calc_DM_batch_edge" href="#segmentation.utils.calc_DM_batch_edge">calc_DM_batch_edge</a></code></li>
<li><code><a title="segmentation.utils.calc_DM_edge" href="#segmentation.utils.calc_DM_edge">calc_DM_edge</a></code></li>
<li><code><a title="segmentation.utils.calc_SDM" href="#segmentation.utils.calc_SDM">calc_SDM</a></code></li>
<li><code><a title="segmentation.utils.calc_SDM_batch" href="#segmentation.utils.calc_SDM_batch">calc_SDM_batch</a></code></li>
<li><code><a title="segmentation.utils.computeContours" href="#segmentation.utils.computeContours">computeContours</a></code></li>
<li><code><a title="segmentation.utils.count_class_voxels" href="#segmentation.utils.count_class_voxels">count_class_voxels</a></code></li>
<li><code><a title="segmentation.utils.cvtColor" href="#segmentation.utils.cvtColor">cvtColor</a></code></li>
<li><code><a title="segmentation.utils.findContours" href="#segmentation.utils.findContours">findContours</a></code></li>
<li><code><a title="segmentation.utils.get_loss_weights" href="#segmentation.utils.get_loss_weights">get_loss_weights</a></code></li>
</ul>
</li>
</ul>
</nav>
</main>
<footer id="footer">
<p>Generated by <a href="https://pdoc3.github.io/pdoc"><cite>pdoc</cite> 0.9.2</a>.</p>
</footer>
</body>
</html>